package com.yonyou.pmclouds.workstopreport.process;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.copyperson.entity.CopyPersonVO;
import com.yonyou.pmclouds.copyperson.rmiitf.ICopyPersonMaintain;
import com.yonyou.pmclouds.workstopreport.entity.WorkStopVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class WorkStopSaveCopyPersonProcess implements SingleProcessor<WorkStopVO> {

    @Autowired
    private ICopyPersonMaintain copyPersonMaintain;

    @Override
    public void process(WorkStopVO vo, WorkStopVO orig) throws BusinessException {
        List<CopyPersonVO> copyPersonVOS = getCopyPersons(vo);
        if(copyPersonVOS != null && copyPersonVOS.size() > 0){
            copyPersonMaintain.insertBatch(copyPersonVOS);
        }
    }
    private List<CopyPersonVO> getCopyPersons(WorkStopVO workStopVO){
        List<CopyPersonVO> copyPersonVOList = workStopVO.getCopyPersons();
        if(copyPersonVOList != null && copyPersonVOList.size() > 0){
            for(CopyPersonVO copyPersonVO : copyPersonVOList){
                copyPersonVO.setPkBill(workStopVO.getPkWorkstopreport());
            }
        }
        return copyPersonVOList;
    }

}
